<template>
    <div  class="warehouse-container">
        <el-button type="primary" @click.native="vueCreate">创建仓库</el-button>
        <warehouseinfo :dialogFormVisible="dialogFormVisible"  :updateOrCreate="updateOrCreate" :editWarehouseInfo="editWarehouseInfo" />
        <el-table
            :data="warehouseList"
            style="width: 100%"
        >
            <el-table-column
                prop="fwhid"
                label="仓库编号"
                width="100"
                sortable 
                />
            <el-table-column
                prop="fwhname"
                label="仓库名称"
                width="200"
                sortable
                />
            <el-table-column
                prop="fwhleadername"
                label="仓库管理员"
                width="200"
                sortable
                />
            <el-table-column
                prop="fwhaddr"
                label="仓库地址"
                width="250"
                sortable
                />
            <el-table-column
                prop="fwhmemo"
                label="备注"
                width="300"
                sortable
                />
            <el-table-column>
                <template slot-scope="scope">
                    <el-button type="primary" size="big" @click="vueDelete(scope.row.fwhid)">删除</el-button>
                    <el-button type="primary" size="big"  @click="vueEdit(scope.row)">编辑</el-button>
                </template>
            </el-table-column>
        </el-table>
    </div>
</template>
<script>
import { getWarehouseList, deleteWarehouse} from '@/api/warehouse'
import warehouseinfo from '@/views/warehouse/information/warehouse/components/WarehouseInfo'

export default {
    components: {
        warehouseinfo
    },
    data () {
        return {
            warehouseList: {},
            searchObj: {},
            dialogFormVisible: false,
            /*true 代表更新，false代表创建*/
            updateOrCreate: false,
            editWarehouseInfo: {},
            
        }
    },
    created() {
        this.fetchData()
    },
    methods: {
        vueCreate() {
            this.dialogFormVisible=true
            this.updateOrCreate=false
        },
        vueEdit(row) {
            this.dialogFormVisible=true
            this.updateOrCreate=true
            this.editWarehouseInfo=row
        },
        vueReset() {
            this.dialogFormVisible=false
            this.updateOrCreate=false
            this.editWarehouseInfo={}
        },
        vueDelete(id) {
            this.$confirm('此操作将永久删除，受否继续？','提示',{
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                deleteWarehouse(id).then(response => {
                    this.fetchData()
                    this.$message({
                        type: 'success',
                        message: '删除成功'
                    })
                })
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消删除'
                })
            })
        },
        fetchData() {
            getWarehouseList(this.searchObj).then(response => {
                this.warehouseList = response.data.warehouseList
            })
        }
    }

}
</script>
<style lang="scss" scoped>
    .warehouse-container {
      margin: 10px 50px 0;
      overflow: hidden;
    }
</style>